package utils.view
{
	import flash.display.Sprite;
	
	import mx.containers.Canvas;
	import mx.core.FlexGlobals;
	import mx.events.ResizeEvent;
	import mx.managers.ISystemManager;
	import mx.managers.PopUpManager;
	
	public class SMLoadStatus extends Canvas
	{
		
		[Bindable]
		private var _label:String= "Aguarde";
		[Bindable]
		private var _message:String = "enquanto efetuamos a operação solicitada."; 
		
		public var _showBox:Boolean = true;
		
		private var ocupado:Ocupado = new Ocupado();
		
		public function SMLoadStatus()
		{
			super();
		}
		
		override public function set label(valor:String) : void
		{
			_label = valor;
			ocupado.label = _label;
		}
		
		override public function get label() : String
		{
			return _label;
		}
		
		public function set message(valor:String) : void
		{
			_message = valor;
			ocupado.message = _message;
		}
		
		public function set color(_color:uint) : void
		{
			ocupado.color = _color;
		}
		
		public function get message() : String
		{
			return _message;
		}
		
		public function set showBox(flag:Boolean):void{
			_showBox = flag;
		}
		
		public function show() : void
		{
			
			addChild(ocupado);
			
			var parent:Sprite = new Sprite();
			
			var sm:ISystemManager = FlexGlobals.topLevelApplication.systemManager as ISystemManager;
			
			var mp:Object = sm.getImplementation("mx.managers.IMarshallPlanSystemManager");
			
			if (mp && mp.useSWFBridge())
			{
				parent = Sprite(sm.getSandboxRoot());
			}					
			else
			{
				parent = Sprite(FlexGlobals.topLevelApplication);
			}	
			
			PopUpManager.addPopUp(this, parent, _showBox);
			
			centerElement(parent.width,parent.height);
			
		}
		
		protected function parent_resize(event:ResizeEvent) : void
		{
			centerElement(event.currentTarget.width, event.currentTarget.height);
		}
		
		private function centerElement(larg:Number,alt:Number) : void
		{
			ocupado.x = (larg/2) - (ocupado.width/2)+50;
			ocupado.y = (alt/2) - (ocupado.height/2);
		}
		
		public function hide() : void
		{
			PopUpManager.removePopUp(this);
		}
		
		
		
	}
}